﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;


public partial class Login : KaohePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MainLogic = new Engine(this);



        try
        {
            string workbookPath = "c:\test.xls";

            Excel.Application oExcel = new Excel.Application();

            /*
            Excel.Workbooks.Open(
                workbookPath,
                0,
                false,
                5, 
                "", 
                "", 
                false, 
                Excel.XlPlatform.xlWindows, 
                "",
                true, 
                false, 
                0, 
                true, 
                false, 
                false);
            */
            Excel.Workbook oBook = oExcel.Workbooks.Add(true);

            oExcel.Cells[1, 1] = "SHET";
            //oBook.Worksheet.Range("a1").Border = "1";
            //Excel.Worksheet.

            Excel.Range r1 = oExcel.get_Range(oExcel.Cells[1, 1], oExcel.Cells[4, 4]); // Get Range            
            r1.Borders.Weight = Excel.XlBorderWeight.xlThin; // Change Weight of border
            r1.Font.Name = "Arial";
            r1.Font.Size = 8;
            r1.Font.Bold = true;
            r1.RowHeight = 20;

            oExcel.get_Range(oExcel.Cells[1, 1], oExcel.Cells[1, 4]).Merge(true); // Merge those cells 

            oExcel.get_Range(oExcel.Cells[1, 1], oExcel.Cells[1, 1]).ColumnWidth = 50;
            
            oExcel.ActiveWorkbook.SaveAs(
                @"c:\testEx.xls", // @"testEx.xls"
                Excel.XlFileFormat.xlAddIn,
                "",
                Missing.Value,
                false,
                false,
                Excel.XlSaveAsAccessMode.xlExclusive,
                Excel.XlSaveConflictResolution.xlUserResolution,
                false,
                Missing.Value,
                Missing.Value,
                true);
            
            oExcel.Quit();


            String x = "ss";
        }
        catch (Exception ex)
        {
            throw ex;
        } 


    }
}
